// JavaScript Document
$(function(){
	var winH = $(window).height();
	var winW = $(window).width();
	var rightBgW = Math.ceil(winW*0.35);
	var num = 1280;
	var numS = 1024;
	//alert(rightBgW);
	
	bgW(winW);
	
	
	$(window).resize(function(){
		var changW = $(this).width();
		
		if(winW != changW){
			bgW(changW);	
		}else{
			bgW(winW);	
		}
    });
	
	function bgW(w){
		
		if( w>=1660){
			$(".right_bg").width(760);
			$(".cont").css("right","140px");
		}else if( w <= num && w >numS ){
			rightBgW = Math.ceil(w*0.5);
			$(".right_bg").width(rightBgW+"px");
			$(".cont").css("right","70px");
		}else if ( w <= numS ){
			rightBgW = Math.ceil(w*0.6);
			$(".right_bg").width(rightBgW+"px");
			$(".cont").css("right","45px");	
		}else{
			rightBgW = Math.ceil(w*0.5);
			$(".right_bg").width(rightBgW+"px");
		}
	}
	
	//账户输入框失去焦点时
	$("#txtLoginEMail").blur(function(){
		checkEmail();
	});
});

var form ;
var showVerifyDiv=false;
function HandleKeyPress(evt)
{
    evt = evt ? evt : event;
	
    if(evt && evt.keyCode == 13)
        DoLogin();
}

function HandleKeyPressToPwd(evt)
{

    evt = evt ? evt : event;

    if(evt && evt.keyCode == 13){
        if(!form){
            getForm();
        }	
        form.txtLoginPwd.focus();
        return false;
    }
}
function checkEmail(){
	$("#txtLoginEMail_e").val("");
    var n = $("#txtLoginEMail").val();
    if(n == ""||n=="邮箱"){
        Msg = '请先输入帐号';
        $("#txtLoginEMail_e").html(Msg);
        $("#txtLoginEMail_e").show();
        return false;
    }else{
        //var mobile = /^(1\d{2}|0[1-9][0-9]{1,2})\d{8}$/;
        var mobile = /^1[0-9]{10}$/;        
        //var email = /^[A-Za-z0-9]+[A-Za-z0-9_\-\.]*[A-Za-z0-9]+@[A-Za-z0-9\-_]+(((\._\-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+)+$/;
        var email = /^[_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]*)*@[A-Za-z0-9\-_]+(((\._-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+)+$/;
        if(!email.test(n))//  邮件登录
        {	
            if(!mobile.test(n)){
                Msg = '账号格式不正确';
                $("#txtLoginEMail_e").html(Msg);
                //$("#txtLoginEMail_e").show();
                return false;     
            }else{
                if(n.length>11){
                    Msg = '账号格式不正确';
                    $("#txtLoginEMail_e").html(Msg);
                   // $("#txtLoginEMail_e").show();
                    return false;
                }else{
                	$.post("regLogServlet",{op:"checkEmail",email:n},function(data){
                		data=parseInt( $.trim(data) );
                		//alert(data);
                		if(data==1){
                			Msg = '直接登录';
                			$("#txtLoginEMail_e").html(Msg);
                            $("#txtLoginEMail_e").show();
                            return false;
                		}else if(data==2){
                			Msg = '邮箱未注册，现在去'+'<a href="register.html" >注册</a>';
                			$("#txtLoginEMail_e").html(Msg);
                            $("#txtLoginEMail_e").show();
                            return false;
                		}
                	});
                }    
            }
        }else{
            if(n.length>40){
                Msg = '账号格式不正确';
                $("#txtLoginEMail_e").html(Msg);
                $("#txtLoginEMail_e").show();
                return false;
            }
        }

    }
    return true;    
}
function DoLogin(){	
	var email = $("#txtLoginEMail").val(); 
    var c=checkEmail();
    if(c==true){
    	var pwd=$("#txtLoginPwd").val();
    	console.info(pwd);
    	$.post("regLogServlet",{op:"userLogin",email:email,pwd:pwd},function(data){
    		data=parseInt( $.trim(data) );
    		if(data==1){
    			location.href='indexsss.jsp';
    		}else if(data==0 || data==4){
    			Msg="邮箱或密码错误...";
    			$("#txtLoginEMail_e").html(Msg);
                $("#txtLoginEMail_e").show();
    		}else if(data==2){ //用户第一次登录
    			location.href='ziliao.html';
    		}
    	});
    }   
}

function getForm(){
    form = document.getElementById("loginForm");
}

window.ready = function(){
    document.getElementById('txtLoginEmail').click = HandleKeyPressToPwd;
}
